package javatunes;

import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class javatunes2remote extends org.eclipse.swt.widgets.Composite {
	private Button playbutton;
	private Button pausebutton;
	private Button previousbutton;
	private Button togglemainwindow;
	private Button nextbutton;
	private Button stopbutton;

	private javatunes2 jt2;
	
	/**
	* Auto-generated method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	public static Shell initRemote(javatunes2 jt2) {
		Display display = Display.getDefault();
		Shell shell = new Shell(display, SWT.ON_TOP | SWT.NO_TRIM);
		javatunes2remote inst = new javatunes2remote(shell, SWT.NULL, jt2);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		return shell;
	}
	
	public javatunes2remote(org.eclipse.swt.widgets.Composite parent, int style, javatunes2 jt2) {
		super(parent, style);
		this.jt2=jt2;
		initGUI();
	}

	private void initGUI() {
		try {
			GridLayout thisLayout = new GridLayout();
			this.setLayout(thisLayout);
			thisLayout.numColumns = 6;
			thisLayout.marginHeight = 0;
			thisLayout.verticalSpacing = 0;
			thisLayout.makeColumnsEqualWidth = true;
			thisLayout.marginWidth = 0;
			thisLayout.horizontalSpacing = 0;
			{
				playbutton = new Button(this, SWT.PUSH | SWT.FLAT | SWT.CENTER);
				GridData playbuttonLData = new GridData();
				playbuttonLData.horizontalAlignment = GridData.FILL;
				playbuttonLData.heightHint = 16;
				playbutton.setLayoutData(playbuttonLData);
				playbutton.setText("Play");
				playbutton.setSize(49, 16);
				playbutton.addSelectionListener(new SelectionAdapter() {
					public void widgetDefaultSelected(SelectionEvent evt) {
						playbuttonWidgetDefaultSelected(evt);
					}
				});
			}
			{
				pausebutton = new Button(this, SWT.PUSH | SWT.FLAT | SWT.CENTER);
				GridData pausebuttonLData = new GridData();
				pausebuttonLData.horizontalAlignment = GridData.FILL;
				pausebuttonLData.heightHint = 16;
				pausebutton.setLayoutData(pausebuttonLData);
				pausebutton.setText("Pause");
				pausebutton.setSize(49, 16);
				pausebutton.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						pausebuttonWidgetSelected(evt);
					}
				});
			}
			{
				stopbutton = new Button(this, SWT.PUSH | SWT.FLAT | SWT.CENTER);
				GridData stopbuttonLData = new GridData();
				stopbuttonLData.horizontalAlignment = GridData.FILL;
				stopbuttonLData.heightHint = 16;
				stopbutton.setLayoutData(stopbuttonLData);
				stopbutton.setText("Stop");
				stopbutton.setSize(49, 16);
				stopbutton.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						stopbuttonWidgetSelected(evt);
					}
				});
			}
			{
				previousbutton = new Button(this, SWT.PUSH
					| SWT.FLAT
					| SWT.CENTER);
				GridData previousbuttonLData = new GridData();
				previousbuttonLData.horizontalAlignment = GridData.FILL;
				previousbuttonLData.heightHint = 16;
				previousbutton.setLayoutData(previousbuttonLData);
				previousbutton.setText("<< Prev");
				previousbutton.setSize(49, 16);
				previousbutton.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						previousbuttonWidgetSelected(evt);
					}
				});
			}
			{
				nextbutton = new Button(this, SWT.PUSH | SWT.FLAT | SWT.CENTER);
				GridData nextbuttonLData = new GridData();
				nextbuttonLData.horizontalAlignment = GridData.FILL;
				nextbuttonLData.heightHint = 16;
				nextbutton.setLayoutData(nextbuttonLData);
				nextbutton.setText("Next >>");
				nextbutton.setSize(49, 16);
				nextbutton.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						nextbuttonWidgetSelected(evt);
					}
				});
			}
			{
				togglemainwindow = new Button(this, SWT.PUSH
					| SWT.FLAT
					| SWT.CENTER);
				togglemainwindow.setText("^Main^");
				GridData togglemainwindowLData = new GridData();
				togglemainwindowLData.horizontalAlignment = GridData.FILL;
				togglemainwindowLData.heightHint = 16;
				togglemainwindow.setLayoutData(togglemainwindowLData);
				togglemainwindow.setSize(47, 16);
				togglemainwindow.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						togglemainwindowWidgetSelected(evt);
					}
				});
			}
			this.layout();
			this.setLocation(400,1);
			this.pack();
			this.getShell().pack();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void togglemainwindowWidgetSelected(SelectionEvent evt) {
		if (jt2.getShell().isVisible()) jt2.getShell().setVisible(false);
		else {
			jt2.getShell().setActive();
			jt2.getShell().setVisible(true);
		}
	}
	
	private void playbuttonWidgetDefaultSelected(SelectionEvent evt) {
		jt2.play(false);
	}
	
	private void pausebuttonWidgetSelected(SelectionEvent evt) {
		jt2.pause();
	}
	
	private void stopbuttonWidgetSelected(SelectionEvent evt) {
		jt2.stop();
	}
	
	private void previousbuttonWidgetSelected(SelectionEvent evt) {
		jt2.previoustrack();
	}
	
	private void nextbuttonWidgetSelected(SelectionEvent evt) {
		jt2.nexttrack();
	}

}
